package 二叉树;

import java.util.ArrayList;

public class Solution4 {
    public int[] postorderTraversal (TreeNode root) {
        //https://www.nowcoder.com/practice/1291064f4d5d4bdeaefbf0dd47d78541
        if (root == null) {
            return new int[0];
        }
        ArrayList<Integer> arrayList = new ArrayList<>();
        int[] retleft = postorderTraversal(root.left);
        int[] retright = postorderTraversal(root.right);
        for (int i : retleft) {
            arrayList.add(i);
        }
        for (int i : retright) {
            arrayList.add(i);
        }
        arrayList.add(root.val);
        int[] ret = new int[arrayList.size()];
        for (int i = 0; i < arrayList.size(); i++) {
            ret[i] = arrayList.get(i);
        }
        return ret;
    }
}
